package com.second.order.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.second.common.pojo.Course;
import com.second.common.pojo.Order;
import com.second.order.dao.OrderDao;
import com.second.order.service.OrderService;
import com.second.order.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Objects;

/**
 * @program: second
 * @description:
 * @author: 胡萌
 * @create: 2023-05-26 16:12
 **/
@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderDao orderDao;

    @Override
    public Page<Order> findByOrderPage(Integer current, Integer pageSize, OrderVo orderVo) {
        Page<Order> page = new Page<>(current, pageSize);
        QueryWrapper<Order> wrapper = new QueryWrapper<>();

        if (StringUtils.hasText(orderVo.getMobile())){
            wrapper.eq("mobile",orderVo.getMobile());
        }
        if (StringUtils.hasText(orderVo.getCourseTitle())){
            wrapper.like("course_title",orderVo.getCourseTitle());
        }
//Objects.nonNull
        if (StringUtils.hasText(orderVo.getGmtCreate())){
            wrapper.ge("gmt_create",orderVo.getGmtCreate());
        }

        if (StringUtils.hasText(orderVo.getGmtModified())){
            wrapper.le("gmt_modified",orderVo.getGmtModified());
        }

        if (StringUtils.hasText(orderVo.getStatus())){
            wrapper.eq("status",orderVo.getStatus());
        }
        if (StringUtils.hasText(orderVo.getOrderNo())){
            wrapper.eq("order_no",orderVo.getOrderNo());
        }
        if (StringUtils.hasText(orderVo.getTeacherName())){
            wrapper.like("teacher_name",orderVo.getTeacherName());
        }

        if (StringUtils.hasText(orderVo.getPayType())){
            wrapper.eq("pay_type",orderVo.getPayType());
        }

        Page<Order> orderPage = orderDao.selectPage(page, wrapper);
        return orderPage;

    }

    @Override
    public Order findOrderAndPayLog(String id) {

        Order orderAndPayLog = orderDao.findOrderAndPayLog(id);

        return orderAndPayLog;
    }


}
